home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
ClutFade 1.3.2
/
C
/
FadeTester Source
/
Shell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-08
|
5KB
|
208 lines
/********************************************************************************
PROJECT: clut_fade.π
FILE: shell.c
PURPOSE: 'clut' fading functions
STATUS: Public Domain Demo.
********************************************************************************/
//================================= INCLUDES ====================================
#include "shell.h"
#include "fade.h"
//================================= FUNCTIONS ===================================
void init_toolbox(void);
void test_window(void);
/*********************************** main ***************************************/
extern
void main(void)
{
init_toolbox();
test_window();
}
/*** main ***/
/********************************** init_toolbox ********************************/
static
void init_toolbox(void)
{
MaxApplZone();
MoreMasters();
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
FlushEvents(everyEvent, 0);
}
/*** init_toolbox ***/
/********************************** test_window *********************************/
static
void test_window(void)
{
DialogPtr d;
GrafPtr g;
short hit;
GDHandle hGD;
CTabHandle hCTab;
long ticks;
short fadeSpeed;
Handle iHandle;
short iType;
Rect iRect;
if (d = GetNewDialog(128, nil, (WindowPtr) -1L))
{
GetPort(&g);
SetPort(d);
ShowWindow(d);
do
{
ModalDialog(nil, &hit);
GetDItem(d,10,&iType,&iHandle,&iRect);
fadeSpeed = GetCtlValue((ControlHandle)iHandle);
switch (hit)
{
// fade all monitors to black
case 2:
// fade out
fade_to_black(fadeSpeed, fadeAll, true);
// wait a few seconds
Delay (120L, &ticks);
// fade in
fade_to_black(fadeSpeed, fadeAll, false);
break;
// fade main monitor to black
case 3:
// fade out
fade_to_black(fadeSpeed, fadeMainOnly, true);
// wait a few seconds
Delay (120L, &ticks);
// fade in
fade_to_black(fadeSpeed, fadeMainOnly, false);
break;
// fade all monitors except main monitor to black
case 4:
// fade out
fade_to_black(fadeSpeed, fadeAllButMain, true);
// wait a few seconds
Delay (120L, &ticks);
// fade in
fade_to_black(fadeSpeed, fadeAllButMain, false);
break;
// fade main monitor to red
case 5:
{
CTabHandle origColors;
GDHandle mainDevice = GetMainDevice();
RGBColor aColor;
// make a copy of the color table so we can restore it later
copy_gdevice_clut(mainDevice,&origColors);
// fade to a color
aColor.red = 65535;
aColor.green = 0;
aColor.blue = 0;
fade_to_color(fadeSpeed,&aColor,mainDevice);
// wait a few seconds
Delay (120L, &ticks);
// fade back to original color table
fade_to_clut(fadeSpeed,origColors,mainDevice);
// dispose the copy we made
DisposeHandle((Handle)origColors);
}
break;
// fade main monitor through rainbow
case 6:
{
CTabHandle origColors;
CTabHandle newColors;
short x;
GDHandle mainDevice = GetMainDevice();
// make a copy of the color table so we can restore it later
copy_gdevice_clut(mainDevice,&origColors);
for (x = 128; x < 135; x++)
{
// get a custom color table (red or blue)
newColors = GetCTable(x);
// limit it to current depth
(**newColors).ctSize = (**origColors).ctSize;
// resize the handle
SetHandleSize((Handle)newColors, GetHandleSize((Handle)origColors));
// fade to the custow color table
fade_to_clut(40,newColors,mainDevice);
ReleaseResource((Handle)newColors);
}
// fade back to original color table
fade_to_clut(40,origColors,mainDevice);
// dispose the copy we made
DisposeHandle((Handle)origColors);
}
break;
// fade to inverted clut
case 7:
{
CTabHandle origColors;
CTabHandle newColors;
RGBColor aColor;
short x;
GDHandle mainDevice = GetMainDevice();
// make a copy of the color table so we can restore it later
copy_gdevice_clut(mainDevice,&origColors);
// make a copy of the color table so we manipulate it
copy_gdevice_clut(mainDevice,&newColors);
// reverse order of colors for a fun effect
for (x = 0; x < (((**newColors).ctSize+1)/2); x++)
{
aColor = (**newColors).ctTable[x].rgb;
(**newColors).ctTable[x].rgb = (**newColors).ctTable[(**newColors).ctSize - x].rgb;
(**newColors).ctTable[(**newColors).ctSize - x].rgb = aColor;
}
// change the ctSeed so we know it is different than original
(**newColors).ctSeed = GetCTSeed();
// fade to it
fade_to_clut(fadeSpeed,newColors,mainDevice);
// wait a few seconds
Delay (120L, &ticks);
// fade back to original color table
fade_to_clut(fadeSpeed,origColors,mainDevice);
// dispose the copy we made
DisposeHandle((Handle)origColors);
}
break;
}
}
while (hit != 1);
SetPort(g);
DisposDialog(d);
}
}
/*** test_window ***/
//===================================== EOF =====================================